﻿@{
    ViewBag.Title = "异常日志";
}
@section headerSection{
    <style>
        #exampleToolbar > .form-group {
            float: left;
            margin: 0;
            margin-left: 5px;
        }
    </style>
}
<div class="animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins" style="margin-bottom: 0px;">
        <div class="ibox-content" style="padding: 5px 20px 0px 20px;">
            <div class="row row-lg">
                <div class="col-sm-12 col-sm-leftRight">
                    <!-- Example Toolbar -->
                    <div class="example">
                        <div class="btn-group hidden-xs" id="exampleToolbar" role="group">
                            <button id="logDetail" type="button" class="btn btn-outline btn-primary">
                                <i class="glyphicon glyphicon-th-large" aria-hidden="true">详细</i>
                            </button>
                            <button id="logDel" type="button" class="btn btn-outline btn-danger">
                                <i class="glyphicon glyphicon-trash" aria-hidden="true">删除</i>
                            </button>
                            <div class="form-group" style="width:250px;">
                                <input id="log_code" name="log_code" type="text" class="form-control" placeholder="异常代码">
                            </div>                         
                            <div class="form-group">
                                <button id="btnSearch" class="btn btn-primary" type="button"><i class="fa fa-search"></i>&nbsp;查询</button>
                            </div>
                            <div class="form-group">
                                <button id="btnHandle" class="btn btn-primary" type="button">
                                    <i class="fa fa-bars"></i>&nbsp;标记处理
                                </button>
                            </div>
                        </div>
                        <table id="exampleTableToolbar" data-mobile-responsive="true" data-radio="true"></table>
                    </div>
                    <!-- End Example Toolbar -->
                </div>
            </div>
        </div>
    </div>
    <!-- End Panel Other -->
</div>
<!-- 详细 -->
<div id="logForm" style="width: 430px; overflow: hidden; display: none;">
    <form class="form-horizontal m-t" id="logFormTable" method="post">
        <div class="form-group">
            <label class="col-sm-4 control-label">异常代码：</label>
            <div class="col-sm-7">
                <input id="logCode" name="logCode" type="text" class="form-control input-sm" disabled="disabled" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-4 control-label">请求参数：</label>
            <div class="col-sm-7">
                <textarea class="form-control" id="params" name="params" rows="3" disabled="disabled"></textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-4 control-label">请求方法：</label>
            <div class="col-sm-7">
                <input id="func" name="func" type="text" class="form-control input-sm" disabled="disabled" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-4 control-label">请求时间：</label>
            <div class="col-sm-7">
                <input id="requestDate" name="requestDate" type="text" class="form-control input-sm" disabled="disabled" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-4 control-label">备注：</label>
            <div class="col-sm-7">
                <textarea class="form-control" id="notes" name="notes" rows="3" disabled="disabled"></textarea>
            </div>
        </div>
    </form>
</div>
@section footSection{
    <script>
        var options, $table;
        var logManager = {
            initPage: function () {
                logManager.initTable();
                logManager.bindEvent();
            },
            //初始化Table
            initTable: function() {
                options = {
                    singleSelect:false,
                    url: ctx + "/SysException/GetLogTable",
                    cutHeight: 5,
                    toolbar: "#exampleToolbar",
                    queryParams: function(params) {
                        params = {
                            //页面大小
                            rows: params.limit,
                            //第几页
                            page: params.offset / params.limit + 1,
                            log_code: $('#log_code').val()
                        }
                        return params;
                    },
                    columns: [
                        {
                            checkbox: true
                        }, {
                            field: '', //第一列序号
                            title: '序号',
                            align: 'center',
                            width: 50,
                            formatter: function(value, row, index) {
                                return index + 1;
                            }
                        }, {
                            field: 'logCode',
                            title: '异常代码',
                            align: 'center'
                        }, {
                            field: 'params',
                            title: '请求参数',
                            align: 'center'
                        }, {
                            field: 'func',
                            title: '异常方法',
                            align: 'center'
                        }, {
                            field: 'requestDate',
                            title: '记录时间',
                            align: 'center',
                            formatter: function (value, row, index) {
                                if (value)
                                    return $.formatDataLong(value);
                                return "";
                            }
                        }, {
                            field: 'isSolve',
                            title: '是否处理',
                            align: 'center',
                            formatter: function (value, row, index) {
                                if (value)
                                    return "<span class='label label-success'>已处理</span>";
                                return "<span class='label label-danger'>未处理</span>";
                            }
                        }, {
                            field: 'handDate',
                            title: '处理时间',
                            align: 'center',
                            formatter: function (value, row, index) {
                                if (value)
                                    return $.formatDataLong(value);
                                return "";
                            }
                        }, {
                            field: 'notes',
                            title: '备注',
                            align: 'center',
                            formatter: function (value, row, index) {
                                if (value && value.toString().length > 15)
                                    return "<span title='" + value + "'>" + value.substring(0, 15) + "...</span>";
                                else
                                    return "";
                            }
                        }]
                }
                $table = tableHelper.initTable("exampleTableToolbar", options);
            },
            //绑定事件
            bindEvent: function() {
                //查询
                $('#btnSearch').click(function () {
                    $table.bootstrapTable('refresh', options);
                });
                //删除
                $('#logDel').on('click', function () {
                    var row = logManager.selections(true);
                    if (!row)
                        return false;
                    var logCode = new Array();
                    $.each(row, function (index, item) {
                        logCode.push(item.logCode);
                    });
                    layer.confirm('您确定要删除当前选择记录？', {
                        btn: ['确定', '取消'] //按钮
                    }, function () {
                        var index = layer.msg("删除中...", { icon: 6, time: 6000 });
                        $.ajax({
                            type: 'post',
                            url: ctx + '/SysException/DelLogById',
                            data: { "logCode": logCode },
                            dataType: 'json',
                            async: false,
                            success: function (data) {
                                layer.close(index);
                                if (data.Statu === 0) {
                                    layer.msg("数据删除成功...");
                                    $table.bootstrapTable('refresh');
                                }
                                else
                                    layer.msg(data.Msg, { icon: 5 });
                            }
                        });
                    }, function () { });
                });
                //详细
                $('#logDetail').click(function () {
                    var rows = $table.bootstrapTable('getSelections');
                    if (rows && rows.length === 0) {
                        layer.msg("未选中行~", { icon: 5 });
                        return false;
                    }
                    var row = rows[0];
                    //清空表单
                    $('#logFormTable').resetHideValidForm();
                    layer.open({
                        title: ['异常详细信息', 'font-size:18px;'],
                        type: 1,
                        content: $('#logForm'),
                        scroll: true, //是否显示滚动条、默认不显示
                        btn: ['确定', '取消'],
                        area: ['480px', '500px'],
                        success: function(li, o) {
                            if (row) {
                                row.requestDate = $.formatDataLong(row.requestDate);
                                $('#logFormTable')[0].reset(); //重置表单
                                $('#logFormTable').LoadForm(row); //表单填充数据
                            }
                        }
                    });
                });
                //标记已处理
                $('#btnHandle').on('click',function(){
                    var row = logManager.selections(true);
                    if (!row)
                        return false;
                    var logCode = new Array();
                    $.each(row, function (index, item) {
                        if (!item.isSolve)
                            logCode.push(item.logCode);
                    });
                    if (!logCode || logCode.length<=0) {
                        layer.msg("当前选中记录已经被标记处理~");
                        return false;
                    }
                    $.ajax({
                        type: 'post',
                        url: ctx + '/SysException/SetHandleById',
                        data: { "logCode": logCode },
                        dataType: 'json',
                        async: false,
                        success: function (data) {
                            if (data.Statu === 0) {
                                layer.msg("数据标记成功...");
                                $table.bootstrapTable('refresh');
                            }
                            else
                                layer.msg(data.Msg, { icon: 5 });
                        }
                    });
                });
            },
            //获取选中行数据
            selections: function (isAll) {
                var row = $table.bootstrapTable('getSelections');
                if (!row || row.length === 0) {
                    layer.msg("数据为空或未选中记录行~", { icon: 5 });
                    return false;
                }
                if (isAll)
                    return row;
                if (row.length > 1) {
                    layer.msg("当前操作不支持多选，请选择一行再操作！", { icon: 5 });
                    return false;
                }
                return row[0];
            }
        }
        $(function() {
            logManager.initPage();
        });
    </script>
}

